package com.cn.wx.dao.impl;

import com.cn.wx.dao.NewsPlateDao;
import com.cn.wx.model.NewsModel;
import com.cn.wx.model.NewsPlateModel;
import com.cn.wx.util.JDBC;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class NewsPlateImpl implements NewsPlateDao {
    @Override
    public List<NewsPlateModel> findAll() {
        String sql = "select * from news_plate ";
        List<NewsPlateModel> list = new ArrayList<>();
        ResultSet resultSet = JDBC.getResultSet(sql);

        try {
            while (resultSet.next()) {
                NewsPlateModel newsPlateModel = new NewsPlateModel();
                newsPlateModel.setId(resultSet.getInt("id"));
                newsPlateModel.setName(resultSet.getString("name"));
                list.add(newsPlateModel);
            }

        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            JDBC.close();
        }


        return list;
    }
}
